home *** CD-ROM | disk | FTP | other *** search
/ The Programmer Disk / The Programmer Disk (Microforum).iso / xpro / c / pro22 / cbgetrf.c < prev    next >
Text File  |  1990-06-20  |  2KB  |  95 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)cbgetrf.c    1.4 - 90/06/20" */
  5.  
  6. /* ansi headers */
  7. #include <errno.h>
  8.  
  9. /* library headers */
  10. #include <blkio.h>
  11. #include <lseq.h>
  12.  
  13. /* local headers */
  14. #include "cbase_.h"
  15.  
  16. /*man---------------------------------------------------------------------------
  17. NAME
  18.      cbgetrf - get cbase record field
  19.  
  20. SYNOPSIS
  21.      #include <cbase.h>
  22.  
  23.      int cbgetrf(cbp, field, buf)
  24.      cbase_t *cbp;
  25.      int field;
  26.      void *buf;
  27.  
  28. DESCRIPTION
  29.      The cbgetrf function reads the specified field from the current
  30.      record of cbase cbp into buf.  buf must point to a storage area
  31.      of size no less than the size of the specified field.
  32.  
  33.      cbgetrf will fail if one or more of the following is true:
  34.  
  35.      [EINVAL]       cbp is not a valid cbase pointer.
  36.      [EINVAL]       field is not a valid field number for
  37.                     cbase cbp.
  38.      [EINVAL]       buf is the NULL pointer.
  39.      [CBELOCK]      cbp is not read locked.
  40.      [CBENOPEN]     cbp is not open.
  41.      [CBENREC]      The record cursor for cbp is null.
  42.  
  43. SEE ALSO
  44.      cbcursor, cbgetr, cbputrf.
  45.  
  46. DIAGNOSTICS
  47.      Upon successful completion, a value of 0 is returned.  Otherwise,
  48.      a value of -1 is returned, and errno set to indicate the error.
  49.  
  50. ------------------------------------------------------------------------------*/
  51. int cbgetrf(cbp, field, buf)
  52. cbase_t *cbp;
  53. int field;
  54. void *buf;
  55. {
  56.     /* validate arguments */
  57.     if (!cb_valid(cbp) || buf == NULL) {
  58.         errno = EINVAL;
  59.         return -1;
  60.     }
  61.  
  62.     /* check if not open */
  63.     if (!(cbp->flags & CBOPEN)) {
  64.         errno = CBENOPEN;
  65.         return -1;
  66.     }
  67.  
  68.     /* validate field argument */
  69.     if (field < 0 || field >= cbp->fldc) {
  70.         errno = EINVAL;
  71.         return -1;
  72.     }
  73.  
  74.     /* check if not read locked */
  75.     if (!(cbp->flags & CBRDLCK)) {
  76.         errno = CBELOCK;
  77.         return -1;
  78.     }
  79.  
  80.     /* check if cursor is null */
  81.     if (lscursor(cbp->lsp) == NULL) {
  82.         errno = CBENREC;
  83.         return -1;
  84.     }
  85.  
  86.     /* read field */
  87.     if (lsgetrf(cbp->lsp, cbp->fldv[field].offset, buf, cbp->fldv[field].len) == -1) {
  88.         CBEPRINT;
  89.         return -1;
  90.     }
  91.  
  92.     errno = 0;
  93.     return 0;
  94. }
  95.